package s.k.gui.webtest;

import org.openqa.selenium.android.AndroidDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.iphone.IPhoneDriver;
import org.openqa.selenium.safari.SafariDriver;

import s.k.gui.webtest.BrowserType;
import s.k.gui.webtest.SeleniumDriver;

public class SeleniumDriver {

	public BrowserType getType() {

		return type;
	}


	private Object engine;

	private BrowserType type;

	public Object getEngine() {

		return engine;
	}

	private SeleniumDriver(Object engine) {

		if (engine == null) {

			this.engine = new InternetExplorerDriver();

		} else {

			this.engine = engine;
		}
	}

	
	public static SeleniumDriver createWebDriverIEEngine() {

		SeleniumDriver driver = new SeleniumDriver(new InternetExplorerDriver());

		driver.type = BrowserType.WebDriverIE;

		return driver;
	}


	public static SeleniumDriver createWebDriverSafariEngine() {

		SeleniumDriver driver = new SeleniumDriver(new SafariDriver());

		driver.type = BrowserType.WebDriverSafari;

		return driver;
	}


	public static SeleniumDriver createWebDriverFireFoxEngine() {

		SeleniumDriver driver = new SeleniumDriver(new FirefoxDriver());

		driver.type = BrowserType.WebDriverFirefox;

		return driver;
	}

	
	public static SeleniumDriver createWebDriverChromeEngine() {

		SeleniumDriver driver = new SeleniumDriver(new ChromeDriver());

		driver.type = BrowserType.WebDriverChrome;

		return driver;
	}

	
	public static SeleniumDriver createWebDriverAndroidEngine() {

		SeleniumDriver driver = new SeleniumDriver(new AndroidDriver());

		driver.type = BrowserType.WebDriverAndroid;

		return driver;
	}

	
	public static SeleniumDriver createWebDriverIphoneEngine() {

		SeleniumDriver driver = null;

		try {
			driver = new SeleniumDriver(new IPhoneDriver());

			driver.type = BrowserType.WebDriverIphone;

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return driver;
	}

	
	public static SeleniumDriver createWebDriverHtmlUnitEngine() {

		SeleniumDriver driver = new SeleniumDriver(new HtmlUnitDriver());

		driver.type = BrowserType.HtmlUnit;

		return driver;
	}

	
	public static SeleniumDriver createWebDriverEngine(BrowserType enginetype) {

		switch (enginetype) {

		case WebDriverIE:

			return createWebDriverIEEngine();

		case WebDriverFirefox:

			return createWebDriverFireFoxEngine();

		case WebDriverChrome:

			return createWebDriverChromeEngine();

		case WebDriverSafari:

			return createWebDriverSafariEngine();

		case WebDriverIphone:

			return createWebDriverIphoneEngine();

		case WebDriverAndroid:

			return createWebDriverAndroidEngine();

		case HtmlUnit:

			return createWebDriverHtmlUnitEngine();

		default:

			return null;
		}
	}

	
	public static SeleniumDriver createEngine(BrowserType enginetype, String url) {

		switch (enginetype) {

		case WebDriverAndroid:

		case WebDriverChrome:

		case WebDriverFirefox:

		case WebDriverIE:

		case WebDriverIphone:

		case HtmlUnit:

			return createWebDriverEngine(enginetype);

		default:

			return null;
		}
	}
}
